<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
  content_for :page_title, @assignment.new_record? ? t(:new_assignment, "New Assignment") : @assignment.title
  content_for :right_side, render(:partial => "assignment_sidebar")
%>

<% if @locked && !@locked[:can_view] %>
  <% js_bundle :module_sequence_footer %>

  <h1><%= @assignment.title %></h1>
  <%= @locked.is_a?(Hash) ? lock_explanation(@locked, 'assignment', @context) : t(:assignment_locked, "This assignment is currently locked.") %>

<% else %>

<%
  css_bundle :assignments
  js_bundle :assignment_show
%>

<% if @assignment.omit_from_final_grade %>
  <div class="alert alert-info omit-from-final-warning">
    {{#t}}This assignment does not count toward the final grade.{{/t}}
  </div>
<% end %>
<div id="assignment_show" class="assignment content_underline_links">
  <% if can_do(@context, @current_user, :read_as_admin) %>
    <div class='assignment-title'>
      <div class='title-content'>
        <h1 class="title">
          <%= @assignment.title %>
        </h1>
      </div>
      <div class='assignment-buttons'>
        <button
          id="assignment_publish_button"
          data-id='<%= @assignment.id %>'
          class='btn <%= "published" if @assignment.published? %> <%= "disabled" unless assignment_publishing_enabled?(@assignment, @current_user) %>'>
        </button>
        <% if can_do(@assignment, @current_user, :update) %>
          <a href="<%= edit_polymorphic_path([@context, @assignment]) %>" class='btn edit_assignment_link'>
            <i class='icon-edit'></i> {{#t}}Edit{{/t}}
          </a>
        <% end %>
        <%= assignment_submission_button(@assignment, @current_user, @current_user_submission) %>
        <% if @assignment.moderated_grading? && can_do(@context, @current_user, :moderate_grades) %>
          <a
            href='<%= course_assignment_moderate_url(@context, @assignment) %>'
            id="moderated_grading_button"
            class='Button'
            style='<%= "display:none" unless @assignment.published? %>'
          >
            {{#t}}Moderate{{/t}}
          </a>
        <% end %>

        <% if @assignment_menu_tools.present? %>
          <a class="al-trigger btn" role="button" aria-haspopup="true" aria-owns="toolbar-1" href="#">
            <i class="icon-settings"></i>
            <i class="icon-mini-arrow-down"></i>
            
          </a>
          <ul id="toolbar-1" class="al-options" role="menu" tabindex="0" aria-hidden="true" aria-expanded="false">
            <%= external_tools_menu_items(@assignment_menu_tools, {link_class: "menu_tool_link", settings_key: :assignment_menu, in_list: true, url_params: {:assignments => [@assignment.id]}}) %>
          </ul>
        <% end %>
      </div>
    </div>
  <% else %>
    <!--Student View-->
    <div class='assignment-title'>
      <div class='title-content'>
        <h1 class="title">
          <%= @assignment.title %>
        </h1>
      </div>
      <div class='assignment-buttons'>
        <span style="display: inline-block">
          <%= render "shared/mark_as_done" %>
        </span>
        <%= assignment_submission_button(@assignment, @current_user, @current_user_submission) %>
      </div>
    </div>
    <ul class='student-assignment-overview'>
      <li>
        <span class='title'><%= t :due_at, 'Due' %></span>
        <span class='value'>
          <span class="date_text">
            <% if @assignment.multiple_due_dates? %>
              <%= multiple_due_date_tooltip(@assignment, @current_user) %>
            <% elsif @assignment.due_at %>
              <% ot(:date_time_by, "%{date} by %{time}", :date => capture { %>
                <span class="display_date"><%= date_string(@assignment.due_at) rescue '' %></span><% }, :time => capture { %>
                <span class="display_time"><%= time_string(@assignment.due_at) rescue '' %></span><% }) %>
            <% else %>
              <%= t :no_due_date, 'No Due Date' %>
            <% end %>
          </span>
        </span>
      </li>
      <li>
        <span class='title'><%= t :points, 'Points' %></span>
        <span class='value'><%= n(round_if_whole(@assignment.points_possible)) || t(:no_points, 'None') %></span>
      </li>
      <% if @assignment.expects_submission? || @assignment.expects_external_submission? %>
        <% turnitin_text = turnitin_active? ? ' ' + t(:turnitin_enabled_short, '(Turnitin enabled)') : '' %>
        <% vericite_text = vericite_active? ? ' ' + t(:vericite_enabled_short, '(VeriCite enabled)') : '' %>
        <li>
          <span class='title'><%= t :submitting, 'Submitting' %></span>
          <span class='value'><%= @assignment.readable_submission_types + turnitin_text %></span>
        </li>
        <% if @assignment.submission_types =~ /online_upload/ && !@assignment.allowed_extensions.blank? -%>
          <li>
            <span class='title'><%= t :submission_types, 'File Types' %></span>
            <span class='value'><%= @assignment.allowed_extensions.to_sentence %></span>
          </li>
        <% end %>
      <% end %>
      {{> views/shared/available_dates}}
      <div class="clear"></div>
    </ul>
  <% end %>

  <div class="clear"></div>

  <% if @locked %>
    <%= @locked.is_a?(Hash) ? lock_explanation(@locked, 'assignment', @context) : t('messages.locked', "This assignment is currently locked.") %>
  <% end %>

  <div class="clear"></div>

  <% description = !@assignment.description.blank? ? public_user_content(@assignment.description) : t('defaults.no_content', "No Content") %>
  <div class="description user_content <%= can_do(@context, @current_user, :read_as_admin) ? "teacher-version" : "student-version" %>"><%= description %></div>

  <% if can_do(@context, @current_user, :read_as_admin) %>
    <!--Teacher view-->

    <form class="form-horizontal bootstrap-form display-only" style="margin-top:18px;">
      <fieldset>
        <div class="control-group">
          <div class="control-label">{{#t}}Points{{/t}}</div>
          <div class="controls">
            <span class="value points_possible"><%= n(round_if_whole(@assignment.points_possible)) || t(:no_points, 'None') %></span>
          </div>
        </div>
        <div class="control-group">
          <div class="control-label"><%= t :submitting, 'Submitting' %></div>
          <div class="controls">
            <span class="value"><%= @assignment.readable_submission_types || t(:no_submission, 'Nothing') %></span>
          </div>
        </div>
        <% if @assignment.submission_types =~ /online_upload/ && !@assignment.allowed_extensions.blank? -%>
          <div class="control-group">
            <div class="control-label"><%= t :submission_types, 'File Types' %></div>
            <div class="controls">
              <span class="value"><%= @assignment.allowed_extensions.to_sentence %></span>
            </div>
          </div>
        <% end -%>
        <% if turnitin_active? %>
          <div class="control-group">
            <div class="control-label"><%= t :turnitin, 'Turnitin' %></div>
            <div class="controls">
              <span class="value"><%= t :turnitin_enabled, 'Turnitin has been enabled for this assignment.' %></span>
            </div>
          </div>
        <% end %>
        <% if vericite_active? %>
          <div class="control-group">
            <div class="control-label"><%= t :vericite, 'VeriCite' %></div>
            <div class="controls">
              <span class="value"><%= t :vericite_enabled, 'VeriCite has been enabled for this assignment.' %></span>
            </div>
          </div>
        <% end %>
      </fieldset>
    </form>

    <table class="ic-Table assignment_dates">
      <thead>
        <tr>
          <th scope="col">{{#t}}Due{{/t}}</th>
          <th scope="col">{{#t}}For{{/t}}</th>
          <th scope="col">{{#t}}Available from{{/t}}</th>
          <th scope="col">{{#t}}Until{{/t}}</th>
        </tr>
      </thead>

      <%= render 'shared/override_list', :assignment => @assignment,
        :user => @current_user %>

    </table>

    <% if can_do(@assignment, @current_user, :update) %>
      <div class="content-box">
        <a
          href="<%= context_url(@context, :context_rubrics_url) %>"
          class="add_rubric_link Button icon-plus"
          style="<%= hidden if @assignment.rubric_association %>"
          role="button"
        >
          <span aria-hidden="true"><%= t 'links.add_rubric', "Rubric" %></span>
          
        </a>
      </div>
    <% end %>

    <div class="course_id" style="display: none;"><%= @context.id if @context && @context.is_a?(Course) %></div>

  <% end %>

  <div style="display: none;">
    <span class="timestamp"><%= @assignment.due_at.to_i %></span>
    <span class="due_date_string"><%= @assignment.due_at.strftime("%m/%d/%Y") rescue "" %></span>
    <span class="due_time_string"><%= @assignment.due_at.strftime("%I:%M%p").downcase rescue "" %></span>
  </div>
</div>

<% end %>

<% if !@locked && can_do(@assignment, @current_user, :submit) %>
  {{> views/submit_assignment}}
<% end %>

<%= render partial: "shared/rubrics_component" %>
